<%@page import="com.situ.web.vo.PageInfo"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.situ.web.entity.Course"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
	<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
	<%-- ${list} --%>
	<table border="1" cellspacing="0" width="400px">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>学分</td>
		</tr>
		<%
			PageInfo pageInfo = (PageInfo)request.getAttribute("pageInfo");
			//List<Course> list = (ArrayList<Course>)pageInfo.getData();
			List<Course> list = (ArrayList<Course>)pageInfo.getList();
			for (Course course : list) {
				// 每遍历一个Course就在table中打印一行数据tr
		%>
				<tr>
					<td><%=course.getId()%></td>
					<td><%=course.getName()%></td>
					<td><%=course.getCredit()%></td>
				</tr>
		<%
			}
		%>
	</table>
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	  	<!-- 上一页开始 -->
	  	<%
	  		if (pageInfo.getPageNo() == 1) {
	  	%>
			    <li class="disabled">
			      <a  href="#" aria-label="Previous">
			        <span aria-hidden="true">&laquo;</span>
			      </a>
			    </li>
	  	<%	
	  		} else {
	  	%>
	  			<li>
			      <a href="<%=request.getContextPath()%>/course?method=selectByPage&pageNo=<%=pageInfo.getPageNo()-1%>" aria-label="Previous">
			        <span aria-hidden="true">&laquo;</span>
			      </a>
			    </li>
		<%
	  		}
	  	%>
	  	<!-- 上一页结束 -->
	  	
	    <%
	    	for(int i = 1; i <= pageInfo.getTotalPage(); i++) {
	   			if (i == pageInfo.getPageNo()) {
	   	%>
				    <li class="active"><a href="#"><%=i%></a></li>
		<%
	   			} else {
	   	%>
				    <li><a href="<%=request.getContextPath()%>/course?method=selectByPage&pageNo=<%=i%>"><%=i%></a></li>
	   	<% 
	   			}
	    	}
	    %>
	    
	    <li>
	      <a href="#" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	    </li>
	  </ul>
	</nav>
</body>
</html>